import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] arr1 = aa(sc);
        int[] arr2 = aa(sc);
        int[] arr3 = new int[arr1.length + arr2.length];
        int[] first = uq(arr1);
        e(first);
        int[] two = uq(arr2);
        e(two);
        System.arraycopy(arr1, 0, arr3, 0, arr1.length);
        System.arraycopy(arr2, 0, arr3, arr1.length, arr2.length);
        int[] three = uq(arr3);
        e(three);
    }

    public static void e(int[] a2) {
        for (int i = 0; i < a2.length; i++) {
            if (i==a2.length-1){
                System.out.print(a2[i]);
            }else{
                System.out.print(a2[i] + " ");
            }
        }
        System.out.println();
    }

    public static int[] uq(int[] Ar1) {
        for (int i = 0; i < Ar1.length - 1; i++) {
            for (int j = 0; j < Ar1.length - 1-i; j++) {
                if (Ar1[j] > Ar1[j + 1]) {
                    int temp = Ar1[j];
                    Ar1[j] = Ar1[j + 1];
                    Ar1[j + 1] = temp;
                }
            }
        }
        return Ar1;
    }

    public static int[] aa(Scanner sc){
        int n = sc.nextInt();
        int[] qq = new int[n];
        for (int i = 0; i < qq.length; i++) {
            qq[i] = sc.nextInt();
        }
        return qq;
    }
}